package com.eusoft.book_manage.util;

import com.eusoft.book_manage.entity.BookType;

import java.util.ArrayList;
import java.util.List;

/**
 * @author eusoft
 * @date 2021/10/20 9:15
 */
public class TreeUtil {

    /**
     * 将List<BookType> 的数据转为 List<TreeNode>，含有isDelete属性
     * @param typeList List<BookType>
     * @return List<TreeNode>
     */
    public static List<TreeNode> formatData(List<BookType> typeList){
        List<TreeNode> treeList = new ArrayList<>();

        typeList.forEach(x->{
            Integer aid = x.getAid();
            String name = x.getName();
            Integer fatherAid = x.getFatherAid();
            if(fatherAid == null)
                fatherAid = 0;
            Boolean isDelete = x.getIsDelete();
            TreeNode treeNode = new TreeNode(aid,name,fatherAid,isDelete);
            treeList.add(treeNode);
        });
        return treeList;
    }

    /**
     * 将List<BookType> 的数据转为 List<TreeNode>,没有isDelete属性
     * @param typeList List<BookType>
     * @return List<TreeNode>
     */
    public static List<TreeNode> formatData2(List<BookType> typeList){
        List<TreeNode> treeList = new ArrayList<>();

        typeList.forEach(x->{
            Integer aid = x.getAid();
            String name = x.getName();
            Integer fatherAid = x.getFatherAid();
            if(fatherAid == null)
                fatherAid = 0;
            TreeNode treeNode = new TreeNode(aid,name,fatherAid);
            treeList.add(treeNode);
        });
        return treeList;
    }
}
